import i18n from "@/locals";
import { getBaseOption } from "./TableBase";
import { getRatioOption } from "./TableRatio";
import { getVolOption } from "./TableVol";

export enum TableType {
    /**大户持仓量多空比 */
    POSITION_RATIO,
    /**大户账户数多空比 */
    ACCOUNT_RATIO,
    /**合约主动买卖量 */
    AUTO_RATIO,
    /**合约持仓量 */
    CONTRACT_HIST,
    /**多空持仓人数比 */
    TOTAL_RATIO,
    /**资金费率 */
    FUNDING_RATE
}

interface POSITION_RATIO {
    symbol: string;
    longShortRatio: string;
    longAccount: string;
    shortAccount: string;
    timestamp: number;
}

interface Prop {
    type: number;
    symbol: string;
    period: string;
    title: string;
    desc: string;
    url: string;
    items: Item[];
    timestampKey: string;
}

interface Item {
    tip: string;
    key: string;
    axis: string;
}

export function ClassifySet(type: TableType | undefined, ary: any, prop: any) {
    let option = {};
    switch (type) {
        case TableType.POSITION_RATIO:
            option = tableA(ary, prop);
            break;
        case TableType.ACCOUNT_RATIO:
            option = tableA(ary, prop);
            break;
        case TableType.AUTO_RATIO:
            option = tableC(ary, prop);
            break;
        case TableType.CONTRACT_HIST:
            option = tableC(ary, prop);
            break;
        case TableType.TOTAL_RATIO:
            option = tableA(ary, prop);
            break;
        case TableType.FUNDING_RATE:
            // console.log('yzt资金费率表格数！！！！！！！',ary);
            
            option = tableB(ary);
            break;
    }
    return option;
}

function tableA(ary: any, prop: Prop) {
    let option: echarts.EChartOption = getRatioOption(ary as any);
    const arrDate = ary as POSITION_RATIO[];
    const names = [
        {
            icon: "circle",
            name: i18n.global.t("message.Position.table.a.c")
        },
        {
            icon: "circle",
            name: i18n.global.t("message.Position.table.a.d")
        },
        {
            icon: "",
            name: i18n.global.t("message.Position.table.a.a")
        }
    ];
    option.legend!.data = names;
    option.series = [];
    // option.tooltip = {
    //     trigger: 'axis',
    //     axisPointer: {
    //       animation: false
    //     }
    // }
    let data = {
        name: names[0].name,
        stack: "Total",
        data: arrDate.map(item => Number(item.longAccount) * 100),
        type: "line",
        emphasis: { disabled: true },
        lineStyle: {
            width: 0
        },
        symbol: "none",
        itemStyle: {
            normal: {
                color: "#0DCB81" //青绿色
            }
        },
        areaStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                    offset: 0,
                    color: "rgba(13,203,129,0.4)"
                },
                {
                    offset: 1,
                    color: "rgba(13,203,129,0.1)"
                }
            ])
        }
    };
    let dataB = {
        name: names[1].name,
        stack: "Total",
        data: arrDate.map(item => Number(item.shortAccount) * 100),
        type: "line",
        emphasis: { disabled: true },
        lineStyle: {
            width: 0
        },
        itemStyle: {
            normal: {
                color: "#F6475D" //红色颜色
            }
        },
        symbol: "none",
        areaStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                    offset: 0,
                    color: "rgba(246,71,93,0.1)"
                },
                {
                    offset: 1,
                    color: "rgba(246,71,93,0.4)"
                }
            ])
        }
    };
    let dataC = {
        name: names[2].name,
        data: arrDate.map(item => Number(item.longShortRatio)),
        type: "line",
        yAxisIndex: 1,
        symbolSize: [5, 5],
        smooth: true
        // itemStyle: {
        //     color: "rgba(255,255,255,0.1)"
        // },
        // lineStyle: {
        //     // color: '#5470C6',
        //     width: 4
        // },
        // itemStyle: {
        //     // color: "#FF0000",
        //     normal: {
        //         color: '#fff', //改变折线点的颜色
        //         lineStyle: {
        //             color: 'rgba(255,255,255,1)' //改变折线颜色
        //         }
        //     }
        // }
    };

    option.series?.push(data as any, dataB as any, dataC);
    // console.log(option,option.series,"echarts配置")
    return option;
}

function tableB(ary: any) {
    let option: echarts.EChartOption = {};    
    option = getBaseOption(ary);
    // console.log('yzt____',option);
    return option;
}

function tableC(ary: any, props: any) {
    let option: echarts.EChartOption = {};
    option = getVolOption(ary, props);
    return option;
}
